package com.test.rocketmq.consumer;

import com.test.rocketmq.bean.MessageEvent;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * 创建事件监听01：通过实现ApplicationListener接口
 *
 * 创建消息的消费,监听消息进行消费
 * */
@Component
public class ConsumerService implements ApplicationListener<MessageEvent> {

    @Override
    public void onApplicationEvent(MessageEvent messageEvent) {
        try{
            List<MessageExt> msgs = messageEvent.getMsgs();
            for(MessageExt msg : msgs ){
                System.out.println("消费消息01："+new String(msg.getBody()));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
